package com.mdc;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author chengfan
 * @create 2017-05-09 下午9:52
 */
public class Interceptor2 implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
            throws Exception {
        System.out.println("Inter2.preHandle在请求处理之前(Controller方法调用之前)调用");
        return true;// 只有返回true才会继续向下执行，返回false取消当前请求
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
                           ModelAndView modelAndView) throws Exception {
        System.out.println("Inter2.postHandle在请求处理之后(Controller方法调用之后)和在视图被渲染之前调用");
    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
            throws Exception {
        System.out.println("Inter2.afterCompletion在整个请求结束之后被调用，也就是在DispatcherServlet渲染了对应的视图之后执行(主要用于资源清理工作)");
    }

}

